# +----------------------------------------------------------------------
# | ChatWork智能聊天办公系统
# +----------------------------------------------------------------------
# | 软件声明: 本系统并非自由软件,未经授权任何形式的商业使用均属非法。
# | 版权保护: 任何企业和个人不允许对程序代码以任何形式任何目的复制/分发。
# | 授权要求: 如有商业使用需求,请务必先与版权所有者取得联系并获得正式授权。
# +----------------------------------------------------------------------
# | Author: ChatWork Team <2474369941@qq.com>
# +----------------------------------------------------------------------
from fastapi import APIRouter, Request, Depends
from hypertext import R, response_json, PagingResult
from apps.api.schemas.agent.know import archive_schema as schema
from apps.api.service.agent.know.archive_service import KnowArchiveService


router = APIRouter(prefix="/archive", tags=["知识库文档接口"])


@router.get("/whole", summary="文档全部", response_model=R[PagingResult[schema.KnowArchiveWholeVo]])
@response_json
async def whole(request: Request, params: schema.KnowArchiveWholeIn = Depends()):
    user_id: int = int(request.state.user_id)
    return await KnowArchiveService.whole(user_id, params)


@router.get("/lists", summary="文档列表", response_model=R[PagingResult[schema.KnowArchiveListVo]])
@response_json
async def lists(request: Request, params: schema.KnowArchiveSearchIn = Depends()):
    user_id: int = int(request.state.user_id)
    return await KnowArchiveService.lists(user_id, params)


@router.get("/detail", summary="文档详情", response_model=R[PagingResult[schema.KnowArchiveDetailVo]])
@response_json
async def detail(request: Request, params: schema.KnowArchiveDetailIn = Depends()):
    user_id: int = int(request.state.user_id)
    return await KnowArchiveService.detail(user_id, params.fid)


@router.post("/inspect", summary="文档检测", response_model=R[PagingResult[schema.KnowArchiveListVo]])
@response_json
async def inspect(request: Request, params: schema.KnowArchiveInspectIn):
    user_id: int = int(request.state.user_id)
    return await KnowArchiveService.inspect(user_id, params.ids)


@router.post("/rename", summary="文档命名", response_model=R)
@response_json
async def rename(request: Request, params: schema.KnowArchiveRenameIn):
    user_id: int = int(request.state.user_id)
    return await KnowArchiveService.rename(user_id, params)


@router.post("/merge", summary="文档合并", response_model=R)
@response_json
async def merge(request: Request, params: schema.KnowArchiveMergeIn):
    user_id: int = int(request.state.user_id)
    return await KnowArchiveService.merge(user_id, params)


@router.post("/delete", summary="文档删除", response_model=R)
@response_json
async def delete(request: Request, params: schema.KnowArchiveFidIn):
    user_id: int = int(request.state.user_id)
    return await KnowArchiveService.delete(user_id, params.fid)


@router.post("/status", summary="文档状态", response_model=R)
@response_json
async def status(request: Request, params: schema.KnowArchiveFidIn):
    user_id: int = int(request.state.user_id)
    return await KnowArchiveService.status(user_id, params.fid)


@router.post("/imports", summary="文档导入", response_model=R)
@response_json
async def imports(request: Request, params: schema.KnowArchiveImportIn):
    user_id: int = int(request.state.user_id)
    return await KnowArchiveService.imports(params, user_id)


@router.post("/parse", summary="文档解析", response_model=R[schema.KnowArchiveParseVo])
@response_json
async def parse(params: schema.KnowArchiveParseIn):
    return await KnowArchiveService.parse(params)
